var config = require('../../../../utils/config.js');
var util = require('../../../../utils/util');
var API_URL = config.API_URL;
var userInfo;
var app = getApp();
Page({
    data: {

    },
    onLoad: function (options) {
        userInfo = my.getStorageSync({key:'user'}).data;
        var that = this;
        my.httpRequest({
            url: API_URL.my_card,
            data: {
                user_id: userInfo.userId
            },
            method: 'POST',
            success: function (res) {
                if (res.data.status == 200) {
                    console.log(res)
                    var cards = res.data.data.cards.map(item => {
                        item.move = false;
                        switch (item.backName) {
                            case "中国民生银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/1.png'; break;
                            case "平安银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/2.png'; break;
                            case "中国银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/3.png'; break;
                            case "中国邮政储蓄": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/4.png'; break;
                            case "光大银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/5.png'; break;
                            case "浙商银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/6.png'; break;
                            case "东亚银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/7.png'; break;
                            case "上海银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/8.png'; break;
                            case "中国工商银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/9.png'; break;
                            case "中国建设银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/10.png'; break;
                            case "中国农业银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/11.png'; break;
                            case "中国交通银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/12.png'; break;
                            case "华夏银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/13.png'; break;
                            case "招商银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/14.png'; break;
                            case "中信实业银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/15.png'; break;
                            case "上海浦东发展银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/16.png'; break;
                            case "广州市商业银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/17.png'; break;
                            case "北京银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/18.png'; break;
                            case "大连银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/19.png'; break;
                            case "宁波银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/20.png'; break;
                            case "青岛银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/21.png'; break;
                            case "深圳发展银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/22/1.png'; break;
                            case "盛京银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/23.png'; break;
                            case "中国人民银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/24.png'; break;
                            case "广发银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/25.png'; break;
                            case "农村信用社": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/26.png'; break;
                            case "天津银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/27.png'; break;
                            case "兴业银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/28.png'; break;
                            case "长安银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/29.png'; break;
                            case "中国农业发展银行": item.img = 'http://nan.jade-box.com/wxapp_img/bank/new/30.png'; break;
                        }
                        return item;
                    })
                    console.log(cards)
                    res.data.data.cards = cards;
                    that.setData(res.data.data);
                } else {
                    util.showNotice('网络错误')
                }
            },
            fail: function (res) {
                util.showNotice('网络错误')
            },
            complete: function (res) { },
        })
    },
    // 选择支付方式
    choose: function (e) {
        //   获取到支付的类型
        var tag = e.currentTarget.dataset.tag;
        var typ = e.currentTarget.dataset.type;
        var account = {};
        switch (typ) {
            case 'wxpay': account.type = 'wxpay'; account.img = '/images/wxpay.png'; account.first = '微信支付'; break;
            case 'commission': account.type = 'commission'; account.img = '/images/money/commission.png'; account.first = '佣金余额支付'; break;
            case 'store': account.type = 'store'; account.img = '/images/money/store.png'; account.first = '店铺余额支付'; break;
        }
        app.globalData.money_account = account;
        console.log(app.globalData)
        my.navigateTo({
            url: '/pages/user/balance/recharge/recharge?tag=' + tag + '&type=' + typ,
        })
    }
})